/*
 * ChatController.java
 * Copyright 2025 Churan Tech, all rights reserved.
 * Churan PROPRIETARY/CONFIDENTIAL, any form of usage is subject to approval.
 */

package com.churan.ai.chat.stream.controller;

import com.churan.ai.core.context.ApiContext;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * Function: chat
 *
 * @author churan
 * @date: 2025年5月20日
 */
@RestController
@RequestMapping(ApiContext.API_PATH)
public class ChatController {

    private final ChatClient chatClient;

    public ChatController(ChatClient chatClient) {
        this.chatClient = chatClient;
    }

    @GetMapping("/chat")
    public String chat(@RequestParam String message) {
        return chatClient.prompt().user(message).call().content();
    }

    @GetMapping(value = "/chat/stream", produces = "text/event-stream")
    public Flux<String> streamChat(@RequestParam String message) {
        return chatClient.prompt().user(message).stream().content();
    }
}
